package com.wjh.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson2.JSON;
import com.wjh.base.ResponseApiData;
import com.wjh.service.IUserService;
import com.wjh.user.request.WebLoginRequest;
import com.wjh.user.response.UserWebLoginResponse;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;

/**
 * 登录 AIP接口
 * 
 * @author wenjianhai
 * @date 2023/6/21
 * @since JDK 17
 */
@Tag(name = "登录 AIP接口", description = "登录 AIP接口")
@Slf4j
@RestController
@RequestMapping("/login")
public class LoginController {

	@Autowired
	private IUserService userService;

	@Operation(summary = "PC端登录", description = "PC端登录")
	@PostMapping("/web")
	public ResponseApiData<UserWebLoginResponse> webLogin(@Validated @RequestBody WebLoginRequest request) {
		log.info("PC端登录-开始.请求参数:{}", JSON.toJSONString(request));
		try {
			return ResponseApiData.success(userService.webLogin(request));
		} catch (Exception e) {
			log.error(String.format("PC端登录-失败.请求参数:%s", JSON.toJSONString(request)), e);
			return ResponseApiData.systemFail(e.getMessage());
		}
	}
}
